<template>
	<view class="card-page">
		<uni-row class="demo-uni-row" :gutter="30">
			<uni-col class="row-box" :span="12" v-for="(item,index) in dataList" :key="index">
				<view class="box" @click="emitOpenPop(item)" :class="{'tag-bg02':item.useStatus === '1','tag-bg03':item.useStatus === '2','tag-bg04':item.useStatus === '3'}">
					<view class="box-header">
						<view>{{item.productName}}</view>
					</view>
					<view class="box-container">
						<view>
							<view v-if="item.useStatus === '0'" class="user-info-box">
								<view class="img-box">
									<image class="user-img" src="@/static/main-icon/user.png" mode=""></image>
									<view class="user-name">{{item.useUserName}}</view>
								</view>
								<view>
									<uni-icons type="right" color="#000" size="20"></uni-icons>
								</view>
							</view>
							<view v-if="item.useStatus === '0'" style="text-align: center;" class="state-tag tag-bg01">
								使用中{{item.useEndTime}}结束</view>
							<view v-else class="user-info-box">
								<view>
									<view v-if="item.useStatus === '1'" class="state-tag tag-bg02">空闲中</view>
									<view v-if="item.useStatus === '2'" class="state-tag tag-bg03">保洁中</view>
									<view v-if="item.useStatus === '3'" class="state-tag tag-bg04">维护中</view>
								</view>
								<view>
									<uni-icons type="right" color="#000" size="16"></uni-icons>
								</view>
							</view>
						</view>
					</view>
				</view>
			</uni-col>
		</uni-row>
	</view>
</template>

<script>
	export default {
		name: "room-item",
		props: {
			dataList: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				
			};
		},
		methods: {
			// 打开父级弹窗
			emitOpenPop(item) {
				const data = item
				this.$emit('openPopEvent', data)
			},
			// 通电
			openLight(item) {
				uni.showModal({
					title: '提示',
					content: '是否确认通电？',
					cancelText: '取消',
					cancelColor: '#666',
					confirmText: '确认',
					confirmColor: '#169bd5',
					success: res => {
						if (res.confirm) {
							this.$request({
								method: 'post',
								url: `/applet/clear/product/openElectronic/${item.productId}`,
								loading: true,
								isEncrypt: false
							}).then(res => {

							}).catch(err => {
								console.log('请求异常：', err)
							})
						}
					}
				})
			},
			// 断电
			closeLight(item) {
				uni.showModal({
					title: '提示',
					content: '是否确认断电？',
					cancelText: '取消',
					cancelColor: '#666',
					confirmText: '确认',
					confirmColor: '#FF4B33',
					success: res => {
						if (res.confirm) {
							this.$request({
								method: 'post',
								url: `/applet/clear/product/closeElectronic/${item.productId}`,
								loading: true,
								isEncrypt: false
							}).then(res => {

							}).catch(err => {
								console.log('请求异常：', err)
							})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.card-page {

		.row-box {
			margin-bottom: 20rpx;
		}

		.box {
			border: 1px solid #EEE;
			border-radius: 20rpx;
			padding: 20rpx;
			box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
			margin-bottom: 20rpx;
			font-size: 32rpx !important;
			height: 260rpx;
			display: flex;
			flex-direction: column;
		}

		.box-header {
			color: #000;
		}

		.box-container {
			display: flex;
			align-items: center;
			justify-content: center;
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.state-tag {
			padding: 6rpx 10rpx;
			font-size: 24rpx;
		}

		.user-info-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10rpx 0;
		}

		.img-box {
			display: flex;
			align-items: center;
			width: calc(100% - 40rpx);

			.user-img {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				margin-right: 20rpx;
				flex-shrink: 0;
			}

			.user-name {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}

		.tag-bg01 {
			color: #00C250;
			background: #d2ffe5;
			border-radius: 10rpx;
		}

		.tag-bg02 {
			color: #169bd5;
			background: #d2f1ff;
			border-radius: 10rpx;
			font-size: 38rpx;
		}

		.tag-bg03 {
			color: #b8741a;
			background: #ffedd4;
			border-radius: 10rpx;
			font-size: 38rpx;
		}

		.tag-bg04 {
			color: #FF4B33;
			background: #ffdbd6;
			border-radius: 10rpx;
			font-size: 38rpx;
		}

	}
</style>